<?php
	include "../include/lib_func.php";
	
	# ambil data dari form
	$nama = $_POST['nama'];
	$email = $_POST['email'];
	$alamat = $_POST['alamat'];
	$telpon = $_POST['telepone'];
	$provinsi = $_POST['provinsi'];
	$pass = MD5($_POST['password']);
	$idmember = substr(MD5($_POST['email']),0,5);
	$kodepos = $_POST['kodepos'];
	
	
	# Pengecekan email
	$cekEmail = cekEmailSama($email);
	if ($cekEmail == 1) {
		echo "<script language='javascript'>alert('Maaf email yang Anda masukan sudah ada pada sistem Kami, silakan Ulangi !');</script>";
		echo "<script language='javascript'>window.location = '../pendaftaran.php'</script>";
	}else{
		$link = koneksi_db();
		$sql  = "insert into member values('$idmember','$email','$nama','$telpon','$kodepos','$provinsi','$alamat','$pass',null)";
		$res  = mysql_query($sql,$link) or exit("Error query: <b>".$sql."</b>.");
		if ($res) {
			echo "<script language='javascript'>alert('Anda telah berhasil menjadi member Kami, Terimakasih !');</script>";
			echo "<script language='javascript'>window.location = '../sign_up.php'</script>";
		}else{
			echo "<script language='javascript'>alert('Terjadi kesalahan dalam proses pendaftaran, Silakan ulangi !');</script>";
			echo "<script language='javascript'>window.location = '../pendaftaran.php'</script>";
		}
	}
?>